<?php

/* @project : Template
 * @auther  : 青云
 * @date    : 2018/1/10
 * @desc    : 用户模型
 */

namespace app\common\model;

use think\Model;

class File extends Base
{

    function getSidAttr($value, $data)
    {
        return think_encrypt($data['id']);
    }

    function getIconAttr($value, $data)
    {
        $file_ext['doc'] = '<i class="iconfont td-file-word"></i>';
        $file_ext['docx'] = '<i class="iconfont td-file-word"></i>';
        $file_ext['ppt'] = '<i class="iconfont td-file-ppt"></i>';
        $file_ext['pptx'] = '<i class="iconfont td-file-ppt"></i>';
        $file_ext['xls'] = '<i class="iconfont td-file-excel"></i>';
        $file_ext['xlsx'] = '<i class="iconfont td-file-excel"></i>';
        $file_ext['jpg'] = '<i class="iconfont td-file-image"></i>';
        $file_ext['png'] = '<i class="iconfont td-file-image"></i>';
        $file_ext['gif'] = '<i class="iconfont td-file-image"></i>';
        $file_ext['pdf'] = '<i class="iconfont td-file-pdf"></i>';
        $file_ext['zip'] = '<i class="iconfont td-file-zip"></i>';
        $file_ext['rar'] = '<i class="iconfont td-file-zip"></i>';
        $file_ext['mp3'] = '<i class="iconfont td-file-audio"></i>';
        $file_ext['wma'] = '<i class="iconfont td-file-audio"></i>';
        $file_ext['avi'] = '<i class="iconfont td-file-video"></i>';
        $file_ext['wmv'] = '<i class="iconfont td-file-video"></i>';
        $file_ext['mp4'] = '<i class="iconfont td-file-video"></i>';

        if (isset($file_ext[$data['ext']])) {
            return $file_ext[$data['ext']];
        } else {
            '<i class="iconfont td-file-other"></i>';
        }
    }

    function getUrlAttr($value, $data)
    {
        $file = $this->find($data['id']);
        if ($file['is_cloud']) {
            $domain = get_system_config('qiniu_domain', 'system');
            $url = $domain . $file['save_path'];
        } else {
            $domain = get_system_config('system_site');
            $upload_path = config('config.upload_path');
            $save_path = $data['save_path'];
        }
        return $url;
    }
}
